package org.jetlinks.pro.notify.rule;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.MapUtils;
import org.jetlinks.pro.notify.DefaultNotifyType;
import org.jetlinks.rule.engine.api.RuleData;
import org.jetlinks.rule.engine.api.RuleDataHelper;
import org.springframework.util.Assert;

import java.util.Map;

@Getter
@Setter
public class RuleNotifierProperties {

    private DefaultNotifyType notifyType;

    private String notifierId;

    private String templateId;

    private Map<String,Object> variables;

    public Map<String,Object> createVariables(RuleData data){
        Map<String,Object> vars= RuleDataHelper.toContextMap(data);
        if(MapUtils.isNotEmpty(variables)){
            vars.putAll(variables);
        }
        return vars;
    }

    public void validate() {
        Assert.notNull(notifyType, "notifyType can not be null");
        Assert.hasText(notifierId, "notifierId can not be empty");
        Assert.hasText(templateId, "templateId can not be empty");

    }
}
